package com.lixi.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author lixi
 * @create 2020-02-15:17:18
 */
public class MyBatisUtil {
    private static SqlSessionFactory factory = null;

    static {
        InputStream is = null;
        try {
            is = Resources.getResourceAsStream("mybatisConfig.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        factory = new SqlSessionFactoryBuilder().build(is);
    }
    public static SqlSession getSqlSession() {
        return factory.openSession();
    }
    public static SqlSession getSqlSession(boolean lea){
        return factory.openSession(lea);
    }
    public static void ClosSqlSession(SqlSession sqlSession) {
        if (sqlSession != null)
            sqlSession.close();
    }
}
